package com.yishun.springboot.web;

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yishun.springboot.pojo.GeneralRecordNumBeans;
import com.yishun.springboot.pojo.LayminiBaseInfoReturnBeans;
import com.yishun.springboot.pojo.TspHaveDevCode;
import com.yishun.springboot.pojo.UploadGWSAddTeam;
import com.yishun.springboot.service.LayminiCAYService;
import com.yishun.springboot.service.LayminiGWSService;

import lombok.extern.slf4j.Slf4j;

import com.yishun.springboot.service.GongWuSuTimedUploadTspService;

/**
 * layui的所有web控制层方法   1231注释，正常使用情况请上班后立即还原取消注释
 * 
 * @author YS
 *
 */
@Controller
@RequestMapping("page")
@Slf4j
public class CAYWebIndexController {

	@Autowired
	LayminiCAYService layminiCAYService;

	// 按项目查询监督工程信息
	@ResponseBody
	@GetMapping("/getGcbyProjToCAY")
	public JSONObject getGcbyProjToCAY(@RequestBody JSONObject jsonObject) throws Exception {
		//pguid 项目 id 必须是
		JSONObject results = new JSONObject();
		
		String pguid = jsonObject.getString("pguid");
		if (pguid == null) {
			results.put("result", "请在RequestBody填写pguid！");
			return results;
		}
		try {

			results = layminiCAYService.GetGcbyProj(jsonObject);
		} catch (Exception e) {
			log.info("e:" + e);
		}

		return results;
	}

	// 分页模糊查询监督项目信息
	@ResponseBody
	@PostMapping("/GetProjInfosToCAY")
	public JSONObject GetProjInfosToCAY(@RequestBody JSONObject jsonObject) throws Exception {
		//curpage当前页 是、name模糊查询关键字(utf-8) 否
		JSONObject results = new JSONObject();
		String curpage = jsonObject.getString("curpage");
		if (curpage == null) {
			results.put("result", "请在RequestBody填写curpage！");
			return results;
		}
	
		try {

			results = layminiCAYService.GetProjInfos(jsonObject);
		} catch (Exception e) {
			log.info("e:" + e);
			// TODO: handle exception
		}

		return results;
	}
	
	
	// 按项目查询监督工程信息（初始化页面以及搜索操作）
		@ResponseBody
		@PostMapping("/InitGetGcbyProjToCAY")
		public JSONObject InitGetGcbyProjToCAY(String serchParamPguid) throws Exception {
			//pguid 项目 id 必须是
			JSONObject jsonObject = new JSONObject();
			JSONObject results = new JSONObject();
			
			 // 请球体参数添加
			if(serchParamPguid == null)
			jsonObject.put("pguid", 66);
			else
			jsonObject.put("pguid", serchParamPguid);
			
			try {

				results = layminiCAYService.GetGcbyProj(jsonObject);
			} catch (Exception e) {
				log.info("e:" + e);
			}

			return results;
		}
	// 分页模糊查询监督项目信息重载页（初始化页面以及搜索操作） 自己看不注释了
		@ResponseBody
		@PostMapping("/InitGetProjInfosToCAY")
		public JSONObject GetProjInfosToCAY(String curpage,String name,String serchParamCurrPage,String serchParamName) throws Exception {
			log.info("currPage:"+curpage+".name:"+name);
			log.info("serchParamCurrPage:"+serchParamCurrPage+".serchParamName:"+serchParamName);
			JSONObject jsonObject = new JSONObject();
			JSONObject results = new JSONObject();
			
			
			//这个里是基于业务以及请求必须的参数做的校改
			if(serchParamCurrPage == null)
				jsonObject.put("curpage", 55);
			try {
				int tempintcurrpage = Integer.valueOf(serchParamCurrPage);
					jsonObject.put("curpage", tempintcurrpage);
					jsonObject.put("name", serchParamName);
			} catch (Exception e) {
				log.info("e:"+e);
				// TODO: handle exception
			}
		
			//这下面是发送请求
			try {

				results = layminiCAYService.GetProjInfos(jsonObject);
//				String curpageIn = results.getString("curpage");
			} catch (Exception e) {
				log.info("e:" + e);
				// TODO: handle exception
			}

			return results;
		}

}
